package com.example.hybridmobiledemo.view;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.hybridmobiledemo.R;
import com.example.hybridmobiledemo.module.main.bean.ComsInfo;
import com.example.hybridmobiledemo.module.main.model.news.content.NewsConActivity;

import java.util.List;

/**
 * @ClassName: ComRvAdapter$
 * @Description: 作用
 * @Author: letquit
 * @CreateDate: 22/10/2021$
 * @Version: 1.0
 */
public class ComRvAdapter extends RecyclerView.Adapter<ComRvAdapter.ViewHolder> {
    private List<ComsInfo> list;

    public ComRvAdapter(List<ComsInfo> list) {
        this.list = list;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_rv_comslist,
                null));
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        ComsInfo info = list.get(position);
        String mUrl = info.getContent();
        holder.tvRvComAuthor.setText(info.getAuthor());
        holder.tvRvComTime.setText(info.getTime());
        String content = info.getContent();
        NewsConActivity.initWebView(mUrl, holder.webRvComContent);
    }

    @Override
    public int getItemCount() {
        return list.size();
    }


    static class ViewHolder extends RecyclerView.ViewHolder {
        TextView tvRvComAuthor, tvRvComTime;
        WebView webRvComContent;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            tvRvComAuthor = itemView.findViewById(R.id.tvRvComAuthor);
            tvRvComTime = itemView.findViewById(R.id.tvRvComTime);
            webRvComContent = itemView.findViewById(R.id.webRvComContent);
        }
    }
}
